import logging.handlers, os

logger = logging.getLogger()
logger.setLevel(logging.DEBUG)

sh = logging.StreamHandler()
sh.setLevel(logging.INFO)
logger.addHandler(sh)

logpath = "../log" + os.sep + "hm.log"
# 设置时间文件处理器
trfh = logging.handlers.TimedRotatingFileHandler(logpath, when="midnight", interval=1, backupCount=7, encoding="utf-8")
# trfh.setLevel(logging.DEBUG)
logger.addHandler(trfh)

fm = "%(asctime)s-%(levelname)s-[%(filename)s-%(funcName)s()-%(lineno)d]-%(message)s"
formatter = logging.Formatter(fm)
trfh.setFormatter(formatter)
sh.setFormatter(formatter)

logging.debug("debug")
logging.info("info")
logging.warning("warning")
logging.error("error")
logging.critical("critical")
